home *** CD-ROM | disk | FTP | other *** search
Text File | 2000-09-28 | 31.1 KB | 1,154 lines | [TEXT/MPS ] |
- /*
- File: ResDump.c
-
- Contains: QuickDraw GX to PostScript conversion code.
- File contains routines for the PrintF type of transmission
- of device codes contained in the resources. These routines
- will be alternate ways to get data into the stream buffers.
-
- Version: Technology: Quickdraw GX 1.1.x
-
- Copyright: © 1990-1997 by Apple Computer, Inc., all rights reserved.
- */
-
- // allow multiple references to single label
- #define resumeLabel(exception)
-
-
- #include <MacMemory.h>
- #include <Errors.h>
- #include <Resources.h>
- #include <TextUtils.h>
- #include <StdArg.h>
- #include <String.h>
- #include <GXMath.h>
- #include "GXToPSBuildConfig.h"
- #include "GXtoPostScript.h"
- #include "GXExceptions.h"
- #include "RDUtil.h"
- #include "IOUtilities.h"
-
-
- //<FF>
- /*******************************************
-
- Function: RDFlushBuffer
-
- Flushes the RD buffer by sending the buffer data message
-
- rdMap: the RD map, yes - this is the only exported routine
- that does not take the parameter block. Oh well,
- what are you gonna do.
-
- ********************************************/
- OSErr RDFlushBuffer(TRDMapHdl rdMap)
- {
- OSErr status;
-
- register TRDMapPtr pRDMap = *rdMap;
-
- if (pRDMap->buffPtr == 0)
- return(noErr);
-
- HLock((Handle)rdMap);
- status = (*rdMap)->psDevice->BufferData(&(pRDMap->buffer[0]), pRDMap->buffPtr, gxNoBufferOptions);
- pRDMap->buffPtr = 0;
-
- HUnlock((Handle)rdMap);
-
- ncheck(status);
- return(status);
-
- }//RDFlushBuffer
-
- //<FF>
- /******************************************
- Function: RDBufferData:
-
- Standard function for buffering Data for the resource dump utility (Not a public call)
-
- data: Pointer to the data to buffer.
- size: Size of the data to buffer.
- pRDMap: A pointer to the resource dump map.
- flags: Resource Dump Utility flags.
-
- ******************************************/
- OSErr RDBufferData(char *data, long size, TRDMapHdl hRDMap, TRDFlags rdFlags);
- OSErr RDBufferData(char *data, long size, TRDMapHdl hRDMap, TRDFlags rdFlags)
- {
-
- OSErr status = noErr;
- TRDMapPtr pRDMap;
- long copySize; // How much we can copy into buffer.
- Ptr inBuff; // Pointer into the buffer.
-
- if (size > kRDBufferSize) { // Don't bother buffering something huge, send message instead.
-
- nrequire(status = RDFlushBuffer(hRDMap), failed_RDBuff);
- status = (*hRDMap)->psDevice->BufferData(data, size, (rdFlags & eRDMakeHex));
- ncheck(status);
-
- } else {
-
- while (size > 0) { // put data into buffer
-
- pRDMap = *hRDMap; // Dereference the handle, may have moved.
-
- inBuff = pRDMap->buffer + pRDMap->buffPtr; // point into the buffer.
- copySize = kRDBufferSize - pRDMap->buffPtr;
-
- if (copySize <= 0) {
-
- status = RDFlushBuffer(hRDMap);
- nrequire(status, failed_RDBuff);
-
- } else { // Copy what we can into the buffer.
-
- if (size < copySize)
- copySize = size;
-
- BlockMoveData(data, inBuff, copySize); // used to be memcpy(inBuff, data, copySize); Cam says this is faster
-
- size -= copySize;
- data += copySize;
- pRDMap->buffPtr += copySize;
-
- }//end if
-
- }//end while
-
- }//end if
-
-
- failed_RDBuff:
- return(status);
-
- }//RDBufferData
-
-
-
- //<FF>
- /******************************************
- Function: RDBufferByte:
-
- Standard function for buffering a single byte of data
-
- aByte: The byte to buffer.
- pRDMap: A pointer to the resource dump map.
- flags: Resource Dump Utility flags.
-
- ******************************************/
- OSErr RDBufferByte( char aByte, TRDMapHdl hRDMap, TRDFlags rdFlags);
- OSErr RDBufferByte( char aByte, TRDMapHdl hRDMap, TRDFlags rdFlags)
- {
- #pragma unused (rdFlags)
-
- register OSErr status = noErr;
- TRDMapPtr pMap;
-
- if ((*hRDMap)->buffPtr == kRDBufferSize) {
-
- nrequire(status = RDFlushBuffer(hRDMap), failed_Flush);
-
- }//end if
-
- pMap = *hRDMap;
- pMap->buffer[pMap->buffPtr] = aByte;
- ++(pMap->buffPtr);
-
- failed_Flush:
- return(status);
-
- }//RDBufferByte
-
-
-
-
-
- //<FF>
- /*
- * converts only fractional part of a fixed number into decimal form.
- */
- short FixFract2Str( Fixed srcNum, char *dstStr );
- short FixFract2Str( Fixed srcNum, char *dstStr )
- {
- long dstNum;
- long shiftIndx;
- short wholeRound;
-
- UInt8 *scratchPtr1;
-
- #define kDecPlaces 4
- #define kMultiplier 10000 // = pow( 10, kDecPlaces )
-
- // we take the fractional part of the source number, add 1 and multiply by 10,000
- // the number we get is guaranteed to fit in a short ( MAXSHORT == 65535 )
- // we round the number ( for improved accuracy ) and then converted to a string.
- // since the number is guaranteed to be five digits long ( we added 1 before multipling
- // by 10,000) then all we have to do to get the “right” thing is to shift the string
- // left by 1.
-
- dstNum = FixRound( FixMul( srcNum + ff(1) , ff( kMultiplier ) ) );
- NumToString( dstNum, (unsigned char *) dstStr );
-
- // the first pass is to see if we rounded to an integer
-
- wholeRound = dstStr[ 1 ] - '1';
-
- // the second pass is to adjust the string lenght because of
- // trailing zeroes
-
- shiftIndx = kDecPlaces;
- scratchPtr1 = (UInt8 *) &dstStr[ kDecPlaces + 1 ]; // + 1 to step over the 1 -- or 2
-
- while( *scratchPtr1-- == '0' )
- --shiftIndx;
-
- dstStr[ 0 ] = shiftIndx;
-
- return( wholeRound );
-
- }//FixFract2Str
-
- //<FF>
- /***********************************************
-
- Function: RDBufferFixedVal
- Converts a fixed point number to text and buffers it.
-
- pMap: pointer to the map.
- paramVal: The fixed value to dump.
-
- ************************************************/
- OSErr RDBufferFixedVal( Fixed paramVal, TRDMapHdl hRDMap, TRDFlags rdFlags);
- OSErr RDBufferFixedVal( Fixed paramVal, TRDMapHdl hRDMap, TRDFlags rdFlags)
- {
- OSErr status;
- register long intPart;
- register Fixed fractPart;
- char fractStr[ 8 ];
- char tempString[ 8 ];
- Boolean wasNegative = false;
- short roundUp;
-
- intPart = (*(short*)(¶mVal)); //get the whole number.
-
- if (paramVal < 0) {
-
- wasNegative = true;
- paramVal = -paramVal; // This will negate the fractional part properly.
- if (paramVal & 0x0000FFFF) // If there was a fractional part:
- ++intPart; // Add one to whole # because the fractional is always + and added to whole #.
-
- }//end if
-
- fractPart = paramVal & 0x0000FFFF; //Get the fraction as a fixed point number.
-
-
-
- if (fractPart != 0) {
-
- roundUp = FixFract2Str(fractPart, fractStr); // Get the fract string, add any round up to int part.
- if (wasNegative)
- intPart -= roundUp;
- else
- intPart += roundUp;
-
- } else {
-
- fractStr[ 0 ] = 0;
-
- }//end if
-
-
- /** Make sure we dump the negative sign if the int part was zero **/
- if (wasNegative && (intPart == 0)) {
-
- tempString[0] = 1;
- tempString[1] = '-';
-
- } else {
-
- NumToString(intPart, (unsigned char *) tempString);
-
- }//end if
-
-
- if (fractStr[ 0 ] != 0) {
-
- tempString[StrLength((unsigned char*)tempString) + 1] = '.'; //stick the decimal point in.
- tempString[0] += 1; //update the length.
-
- } else if (intPart == 0) { // Make sure we have a zero string
-
- tempString[0] = 1;
- tempString[1] = '0';
-
- }//end if
-
-
- status = RDBufferData(&(tempString[1]), StrLength((unsigned char*)tempString), hRDMap, rdFlags); //dump it.
- nrequire(status, failed_Buff);
-
- //Dump the fractional part as a decimal.
-
- if (fractStr[ 0 ] != 0)
- status = RDBufferData(&(fractStr[2]), StrLength((unsigned char*)fractStr), hRDMap, rdFlags); //Blow it out.
-
-
- failed_Buff:
-
- return(status);
-
- }// RDBufferFixedVal
-
-
-
-
-
- //<FF>
- /**************************************
- Routine: RDBufferSubstituteString
-
- Dumps a %s string parameter, substituting
- characters as indicated by the call to
- RDSetSubstitutions.
-
- string: Pointer to the string to dump.
- length: How many characters in the string.
- pRDMap: pointer to the map record.
- rdFlags: The buffer flags to use.
-
- ***************************************/
- OSErr RDBufferSubstituteString(Ptr string, long length, TRDMapHdl hRDMap, TRDFlags rdFlags);
- OSErr RDBufferSubstituteString(Ptr string, long length, TRDMapHdl hRDMap, TRDFlags rdFlags)
- {
- OSErr status = noErr;
- TRDMapPtr pRDMap;
- long blockLen; //length of a block to dump.
- Ptr beginBlock; //beginning of a block to dump.
- Ptr inString;
- Ptr endString;
- long index; //index of character.
- Handle hSubst; //Substitution array handle.
- Ptr pSubst; //dereference it.
- Boolean mustSubst; //should we substitute?
- short nSubs; //How many substitutions are there?
- short iSub; //substitution index.
- unsigned long theChar;
-
-
- pRDMap = *hRDMap;
- nSubs = pRDMap->nSubs;
- hSubst = pRDMap->hCharSubstitute;
- HLockHi(hSubst); //Must be locked becuase we call RDBufferData on it.
-
- endString = string + length;
- beginBlock = string;
- index = 0;
-
-
- /***********
- Buffer the string, using substitution:
- Build blocks that end, either at a character that must
- be substituted or at the end of the string,
- Dump the block, and the block ended at a substitution,
- Dump the substitution string.
- ***********/
-
- while ( index < length ) {
-
- inString = beginBlock;
- blockLen = 0;
-
- /** Build up a block of characters needing no substitution **/
- mustSubst = false;
- while ( (inString < endString) && !mustSubst) {
-
- /*** Check the current character against substitution array. ***/
-
- //First do quick elimination against substitution bit array.
- // use hRDMap instead of pRDMap cause buffering can move memory.
-
- theChar = (unsigned long)*(unsigned char *)inString;
- mustSubst = BITTST((*hRDMap)->subsBits, theChar) != 0;
-
- // if we failed the bit test, find out which character in the substitution list.
- if (mustSubst) {
-
- pSubst = *hSubst; //point into the substitution array.
-
- for (iSub = nSubs-1; iSub >= 0; --iSub) {
-
- if (*inString != *pSubst++) // the ++ moves past substitution char to pstring.
- pSubst += *(UInt8*)pSubst + 1; //get to next substitution by adding length + 1
- else
- break; //If we found it, force exit of loop.
-
- }//end for
-
- } else { //update the pointers if we are still in a block.
-
- ++blockLen;
- ++inString;
-
- }//end if
-
- }//end while
-
- //If we have a block, blow it out.
- if (blockLen > 0) {
-
- status = RDBufferData(beginBlock, blockLen, hRDMap, rdFlags);
- nrequire(status, failed_buff);
-
- }//end if
-
- /******
- If we stopped at a substitution, substitute the character!
- The pSubst pointer is now pointing to the pascal string we should
- substitute with, so dump it.
- *******/
- if (mustSubst) {
-
- status = RDBufferData(&(pSubst[1]), (UInt8)pSubst[0], hRDMap, rdFlags);
- nrequire(status, failed_buff);
-
- }//end if
-
- beginBlock += blockLen + 1;
- index += blockLen + 1;
-
- }//end while
-
- failed_buff:
-
- HUnlock(hSubst);
-
- return(status);
-
- }//RDBufferSubstituteString
-
- //<FF>
- /*********************************
- Routine RDGetIndPstring:
-
- Finds the offset of an Indexed pstring element in the resource.
-
- hResource: the resource to dissect.
- index: the index of the desired element.
- offset: The byte offset into the resource for that element.
-
- **********************************/
- OSErr RDGetIndPstring(Handle hResource, short index, long *offset);
- OSErr RDGetIndPstring(Handle hResource, short index, long *offset)
- {
- register long byteCount; //byte count into resource.
- register char *pByte; //pointer into the resource.
- register short i; //loop counter.
- register long j; //internal offset
-
- pByte = *hResource; //Point to the beginning of the resource which
- // should contain the number of elements in the array.
-
-
- require( ( index <= *(short*)(pByte) ) , failed_indexTooBig);
-
- /** Find the offset **/
-
- j = sizeof(short);
- pByte += sizeof(short); //skip past the string count.
-
- for (i = 0; i < index; i++) { //Loop through the strings to get the offset.
-
- byteCount = 1 + *(UInt8*)pByte; //Get the length of the next string.
- j += byteCount; //add the length to the offset.
- pByte += byteCount; //update the pointer.
-
- }//end for
-
- *offset = j;
-
- return(noErr);
-
- failed_indexTooBig:
- return(resNotFound);
-
- }//RDGetIndPstring
-
- //<FF>
- /******************************************************************
- Function: RDGetResource:
-
- Called from RDResPrintf to get the resource containing the string to parse.
- The resource is either obtained from the cache hanging off of the map
- or from FetchResource.
-
- pRDMap: Pointer to the RDMap record.
- params: the parameter block.
- h: returned handle for resource.
-
- *******************************************************************/
- OSErr RDGetResource(TRDMapHdl hRDMap, TRDParams *params, Handle *h);
- OSErr RDGetResource(TRDMapHdl hRDMap, TRDParams *params, Handle *h)
- {
- OSErr status;
- // short currResRef; //refnum for current resource file.
- Handle hResource;
- TRDMapPtr pRDMap;
-
-
- // currResRef = CurResFile();
-
- pRDMap = *hRDMap;
-
- hResource = pRDMap->hLastResource;
- if ((hResource == nil) || (params->resType != pRDMap->lastResType)
- || (params->resID != pRDMap->lastResID) ) {
-
- hResource = GetResource(params->resType, params->resID);
- nrequire(status = ResError(), failed_GetRes);
-
- pRDMap = *hRDMap; // Get it again, getresource could have moved stuff.
-
- pRDMap->hLastResource = hResource;
- pRDMap->lastResID = params->resID;
- pRDMap->lastResType = params->resType;
- // pRDMap->lastResRef = currResRef;
-
- //flag invalid offset and index.
-
- pRDMap->lastOffset = -1;
- pRDMap->lastResIndex = -1;
-
- } else {
-
- if (*hResource == nil)
- LoadResource(hResource);
-
- status = ResError();
- nrequire (status, failed_GetRes);
-
- }//end if
-
- *h = hResource;
-
- failed_GetRes:
-
- return(status);
-
- }//RDGetResource
-
-
-
-
-
- //<FF>
- /******************************************************************
-
- PUBLIC ROUTINES
-
- *******************************************************************/
-
- /***********************************************
- Routine RDInit:
-
- This routine is used Initialize the Resource Dump Utility for a client.
-
- rdMap: A map is allocated and returned to the client, client passes to other routines.
-
- *************************************************/
- OSErr RDInit(CGXtoPostScriptDevice* psDevice, TRDMapHdl *rdMap)
- {
- OSErr status;
- TRDMapPtr pRDMap;
-
- // Allocate the memory for the map
- status = PrNewHandleClear((Handle*)rdMap, sizeof(TRDMapRec));
-
- nrequire(status, failed_AllMap);
-
- pRDMap = *(TRDMapHdl)*rdMap;
-
- pRDMap->xySep = 0x20; //the default seperator is a space.
- pRDMap->psDevice = psDevice; // Use this for calling BufferData.
-
- /**********************
-
- These taken care of by PrNewHandleClear
-
- pRDMap->nSubs = 0;
- pRDMap->hCharSubstitute = nil;
- pRDMap->hLastResource = nil;
- pRDMap->lastResID = nil;
- pRDMap->buffPtr = 0;
-
- ***********************/
-
-
- failed_AllMap:
-
- return(status);
-
- }//RDInit
-
-
- //<FF>
- /***********************************************
- Routine RDShutdown:
-
- This routine is used shut down the Dump Utility for a client.
-
- rdMap: The resource dump map identifying the client.
-
- *************************************************/
- OSErr RDShutdown(TRDMapHdl rdMap)
- {
- Handle h;
- OSErr status;
-
- status = RDFlushBuffer(rdMap);
-
- h = (*rdMap)->hCharSubstitute;
- DisposeHandle(h);
- DisposeHandle((Handle)rdMap);
-
- return(status);
-
- }//RDShutdown
-
- //<FF>
-
-
- /***********************************************
- Routine RDResBDump:
-
- This routine is used to dump binary data from a wstring resource.
-
- params: RD Parameter block.
- *************************************************/
- OSErr RDResBDump(TRDParams *params)
- {
- TRDMapHdl hMap; //handle to the map.
- OSErr status; //error status.
- Handle hResource; //Handle to the resource.
- unsigned short size; //How big is the data?
- SInt8 flags; //Handle flags.
-
- check(params);
-
- /*** Try to get the resource. ***/
- status = FetchResource(params->resType, params->resID, &hResource);
- nrequire(status, failed_GetRes);
-
- /** Lock the resource **/
- flags = HGetState(hResource);
- HLock(hResource);
-
- size = *(unsigned short*)(*hResource); //Get the length from the first 2 bytes.
-
- hMap = (params->rdMap);
- status = (*hMap)->psDevice->BufferData(*hResource + sizeof(short), size, (params->rdFlags & eRDMakeHex));
- nrequire(status, failed_Buffer);
-
- HSetState(hResource, flags);
-
- failed_Buffer:
- failed_GetRes:
- return(status);
-
- }//RDResBDump
-
-
- //<FF>
- /**************************************
- Routine RDResStrListDump
-
- Used to dump all strings in an indexed pstring
- resource.
-
- params: RD Parameter block.
- termString: Terminator string (pascal string) for each string in the resource.
- If nil, no character will be output.
-
- ****************************************/
- OSErr RDResStrListDump(TRDParams *params, char *termString)
- {
- OSErr status = noErr; //error status
- Handle hResource; //handle for the resource.
- TRDMapHdl hMap;
- short nString; //Number of strings in resource.
- short i; //loop counter.
- char* pByte; //pointer into resource.
- long byteCount;
- SInt8 flags;
-
- status = FetchResource(params->resType, params->resID, &hResource);
- nrequire(status, failed_GetRes);
-
-
- /** Lock the resource **/
- flags = HGetState(hResource);
- HLock(hResource);
-
- hMap = (params->rdMap);
-
- pByte = *hResource;
-
- nString = *(short*)(pByte); // Get the number of strings.
-
- /** Find the offset **/
- pByte += sizeof(short); //skip past the string count.
-
- for (i = nString - 1; i >= 0; --i) { //Loop through strings and dump em.
-
- byteCount = *(UInt8*)pByte++; //Get the length of the next string.
-
- status = RDBufferData(pByte, byteCount, hMap, params->rdFlags);
- nrequire(status, failed_buff);
-
- //Output the termination character after each string.
-
- if (termString != nil) {
-
- status = RDBufferData(&(termString[1]), StrLength((unsigned char*)termString), hMap, params->rdFlags);
- nrequire(status, failed_buff);
-
- }//end if
-
- pByte += byteCount; //update the pointer.
-
- }//end for
-
- status = RDFlushBuffer(params->rdMap);
- ncheck(status);
-
- failed_buff:
-
- HSetState(hResource, flags);
-
- failed_GetRes:
- return(status);
-
- }//RDResStrListDump
-
-
- //<FF>
- /*********************************
- Routine RDResPrintf:
-
- Used to dump a resource that requires parameter substitution.
- Will work for those that don't have parameters also.
-
- The resources are Printf type strings:
-
- %d will substitute for an integer.
-
- %s will substitute for a string. (actually 2 parameters must be passed for
- each %s - the first is the pointer to the string, the second is the length.
-
- %h will substitute for hex data. (actually 2 parameters must be passed for
- each %h - the first is the pointer to the data, the second is the length.
-
- %f will substitute for a fixed point number (buffered in floating point format).
-
- %p will substitute a fixed point point, using the map's seperation character between
- X and Y.
-
- %q will substitute a Pascal string. Same substitutions as for %s.
-
- %b will substitute a Boolean with "T" or "F". (note, for PostScript clients, you must define /T to be true and /F to be false
- before using this substitution.
-
- The Backslash (\) character is used for quoting, so if you want to output a % character
- use \% (Although a % that is not followed by a parameter specification will simply be
- output, too.
-
-
- params: RD parameter block.
- resIndex: Index of the string within the resource.
- ... The parameters to substitute in the string resource.
-
- ***********************************/
- OSErr RDResPrintf(TRDParams *params, ...)
- {
- TRDMapHdl hRDMap;
- TRDMapPtr pRDMap;
- OSErr status; //error status.
- Handle hResource; //Handle for the resource.
- long offset; //Offset into the resource.
- short strLen; //length of the particular string.
- short blockLen; //length of a string block.
- char *rString; //The string from the resource to dump.
- char *endOfString; //Address of the end of the string
- char *inString; //next character in string.
- char *beginBlock; //Beginning of a block to pass.
-
- va_list paramPtr; //Pointer to next paramter.
- long paramVal; //parameter value.
-
- SInt8 flags;
-
- char tempString[12]; //for NumToString, a long can't be more than 10 digits.
- // plus one for length byte and another for the sign.
- Boolean mustSubstitute;
-
-
- status = noErr;
-
- hRDMap = (params->rdMap);
- pRDMap = *hRDMap;
-
- mustSubstitute = ((params->rdFlags & eRDCharSubs) != 0) && (pRDMap->nSubs > 0);
-
- /** Set up for variable parameter list **/
- va_start(paramPtr, params);
-
- /*** Try to get the resource. ***/
- status = RDGetResource(hRDMap, params, &hResource);
- nrequire (status, failed_GetRes);
-
- /** Lock the resource **/
- flags = HGetState(hResource);
- HLock(hResource);
-
-
- pRDMap = *hRDMap; // Grab pointer to map again, RDGetResource could have moved memory.
-
- //Get the offset of the element of the resource desired (either from cache or search for it).
-
- if (pRDMap->lastResIndex == params->resIndex) {
-
- offset = pRDMap->lastOffset;
-
- } else {
-
- status = RDGetIndPstring(hResource, params->resIndex, &offset);
- nrequire(status, failed_GetInd);
-
- pRDMap->lastOffset = offset;
- pRDMap->lastResIndex = params->resIndex;
-
- }//end if
-
- //Now that we know where, get the pascal string out of the resource.
- rString = (char*)(*(unsigned long*)hResource + offset);
-
- //Prepare to parse for parameters.
- strLen = (UInt8)(rString[0]);
- inString = rString + 1;
- endOfString = inString + strLen - 1;
-
- /****
- Parse it: Build blocks of the string to send out. A block ends at a parameter
- Substitution or the end of the string.
- The substitutions themselves are also dumped as blocks.
- ****/
-
- while (inString <= endOfString) {
-
- blockLen = 0;
- beginBlock = inString; //beginning of next string block to dump.
-
- /** Build the next block of characters that need no parsing **/
- while ((*inString != '%') && (*inString != '\\') && (inString <= endOfString)) {
-
- ++blockLen;
- ++inString;
-
- }//end while
-
- /*** Blow out the current block. ****/
-
- if (blockLen > 0) {
-
- status = RDBufferData(beginBlock, blockLen, hRDMap, params->rdFlags);
- nrequire (status, failed_buffering1);
-
- }//end if
-
- if (inString <= endOfString) { //must have stopped because of parsable character.
-
- /*****************
- Parse the character we stopped on
- ******************/
-
- if (*inString == '\\') { // If we hit the quote character, output the next byte
-
- status = RDBufferByte(*(++inString), hRDMap, params->rdFlags);
- ++inString; //Get ready for next block.
-
- } else { //If we stopped before end of string then we must be at a '%' so parse parameters.
-
- ++inString; //skip to the character after where we stopped so we can parse next block.
-
- switch(*inString++) {
-
- case 'b': //parameter is long value for boolean. output F for zero, otherwise T
- paramVal = va_arg(paramPtr, long); //get the boolean value
- status = RDBufferByte( paramVal ? 'T' : 'F', hRDMap, params->rdFlags); // buffer 'T' or 'F' based on value.
- break;
-
- case 'd': //parameter is an integer.
-
- paramVal = va_arg(paramPtr, long); //get the integer.
- NumToString(paramVal, (unsigned char *) tempString); //convert it to a string.
-
- status = RDBufferData(&(tempString[1]), StrLength((unsigned char*)tempString),
- hRDMap, params->rdFlags); //Blow it out.
- break;
-
- case 'f': //parameter is a fixed point number.
-
- paramVal = (long) va_arg(paramPtr, Fixed); //get the fixed number.
- status = RDBufferFixedVal(paramVal, hRDMap, params->rdFlags); //buffer it.
- break;
-
- case 'p': //parameter is a gx graphics point.
-
- paramVal = (long) va_arg(paramPtr, gxPoint*);
-
- //Output the X value.
- status = RDBufferFixedVal(((gxPoint*)paramVal)->x, hRDMap, params->rdFlags);
- nrequire (status, failed_buffering2);
-
- //output a the seperator between x and y
- status = RDBufferByte((*hRDMap)->xySep, hRDMap, params->rdFlags);
- nrequire (status, failed_buffering3);
-
- //Output the Y value.
- status = RDBufferFixedVal(((gxPoint*)paramVal)->y, hRDMap, params->rdFlags);
-
- break;
-
- case 's': //parameter is a string.
-
- beginBlock = va_arg(paramPtr, char*); //get the pointer.
- paramVal = va_arg(paramPtr, long); //get the length.
-
- if (mustSubstitute) { //do character substituion if needed.
-
- status = RDBufferSubstituteString(beginBlock, paramVal, hRDMap, params->rdFlags);
-
- } else { //just dump the string normally.
-
- status = RDBufferData(beginBlock, paramVal, hRDMap, params->rdFlags);
-
- }//end if
-
- break;
-
- case 'q': // parameter is a pascal string.
-
- beginBlock = va_arg(paramPtr, char*); // Get pointer to the string.
- paramVal = (unsigned char)(*beginBlock++); // Get the length, skip to first byte.
-
- if (mustSubstitute) { //do character substituion if needed.
-
- status = RDBufferSubstituteString(beginBlock, paramVal, hRDMap, params->rdFlags);
-
- } else { //just dump the string normally.
-
- status = RDBufferData(beginBlock, paramVal, hRDMap, params->rdFlags);
-
- }//end if
-
- break;
-
- case 'h': //parameter is binary data, convert to hex.
-
- beginBlock = va_arg(paramPtr, char*); //get the pointer.
- paramVal = va_arg(paramPtr, long); //get the length.
-
- nrequire(status = RDFlushBuffer(hRDMap), failed_buffering4); // flush previous stuff.
- status = (*hRDMap)->psDevice->BufferData(beginBlock, paramVal, params->rdFlags | eRDMakeHex);
-
- break;
-
-
- default: //If none of the substitution characters followed the %, send the '%'
- // And start parsing again at the character right after it.
-
- inString -= 2; //Move back to the % character.
-
- status = RDBufferByte(*inString++, hRDMap, params->rdFlags); //Blow it out.
-
- }//end switch
-
- }//end if
-
- }//end if
-
- nrequire(status, failed_buffering5);
-
- } //end while
-
- if (!(params->rdFlags & eRDNoAutoFlush))
- status = RDFlushBuffer(hRDMap);
-
- ncheck(status);
-
- failed_buffering1:
- failed_buffering2:
- failed_buffering3:
- failed_buffering4:
- failed_buffering5:
-
- va_end(paramPtr);
-
-
- failed_GetInd:
-
- HSetState(hResource, flags);
-
- failed_GetRes:
-
- return(status);
-
- }//RDResPrintf
-
- //<FF>
-
-
- /*********************************
- Routine: RDSetSubstitutions
-
- This routine is called to set the string substitution
- for RDResPrintf to use for %s parameters.
-
- rdMap: The Client's map.
- nSubs: How many substitutions we're specifying.
- ... The list of substitutions. char, spstring, char, pstring...
-
- ************************************/
- OSErr RDSetSubstitutions(TRDMapHdl rdMap, long nSubs, ...)
- {
- register short i; //loop counter.
- OSErr status = noErr;
- va_list paramPtr; //Pointer to next paramter.
- long paramVal; //value of the parameter.
- long memSize; //Memory size to allocate.
- UInt8 subLen; //length of substitution string.
- Handle hSubs;
- Ptr pSubs;
- Ptr pSubsBits;
- UInt8 *pMask;
-
-
- /** Clear out the substitution bit mask **/
- pMask = (*rdMap)->subsBits;
- memset(pMask, 0, 32);
-
- /*****
- Figure out how much memory to allocate for the substitutions
- by traversing the parameter list.
- ******/
- memSize = 0;
- va_start(paramPtr, nSubs);
- for (i = nSubs-1; i >=0; --i) {
-
- paramVal = va_arg(paramPtr, long); //skip the byte to substitute
- paramVal = (long) va_arg(paramPtr, UInt8*); //get the length of the substitution string.
-
- memSize += 2 + *(UInt8*)paramVal; //add size of string, 1 for the byte, 1 for length byte.
-
- }//end for
-
- va_end(paramPtr);
-
- /** Now try to allocate the memory for the new substitution array. **/
-
- hSubs = (*rdMap)->hCharSubstitute;
-
- if (hSubs == nil) {
-
- status = PrNewHandle(&hSubs, memSize);
- (*rdMap)->hCharSubstitute = hSubs;
-
- } else {
-
- status = PrSetHandleSize( hSubs, memSize);
-
- }//end if
- nrequire (status, failed_AllocNewSubs);
-
- pSubs = *hSubs;
-
- /* Now retraverse the parameter list and load the handle with the substitutions */
- va_start(paramPtr, nSubs);
-
- pSubsBits = (char *) (*rdMap)->subsBits;
-
- for (i = nSubs-1; i >= 0; --i) {
-
- paramVal = (long) va_arg(paramPtr, char*); //get the byte to substitute
- *pSubs++ = (char)paramVal; //stick it in the array.
-
- /** Set the bit in the array of substitution characters **/
-
- BITSET(pSubsBits, (UInt8)paramVal);
-
-
- paramVal = (long) va_arg(paramPtr, char*); //get the pstring to substitute for
- subLen = *(UInt8*)paramVal; // get the length of the pstring.
-
- BlockMoveData((char*)paramVal, pSubs, subLen + 1); //stick it in the array.
-
- pSubs += (subLen + 1); //move to next position in array.
-
- }//end for
-
- va_end(paramPtr);
-
- (*rdMap)->nSubs = nSubs;
-
-
- failed_AllocNewSubs:
-
- return(status);
-
- }//RDSetSubstitutions
-
-
- //<FF>
- /****************************************************
- Funciton: RDSetXYSep
-
- Set the character that will be used to seperate the x and y values
- in a %p formatted point.
-
- rdMap: The client's map.
- theChar: The character to use as the seperator.
-
- ****************************************************/
-
- OSErr RDSetXYSep(TRDMapHdl rdMap, char theChar)
- {
- check(rdMap);
-
- (*rdMap)->xySep = theChar;
- return noErr;
-
- }//RDSetXYSep
-
- //<FF>
- /****************************************************
- Funciton: RDInvalResCache
-
- Invalidates the cache used by RDResPrintf.
-
- rdMap: The client's map.
-
- ****************************************************/
- OSErr RDInvalResCache(TRDMapHdl rdMap)
- {
- register TRDMapPtr pMap = *(TRDMapHdl)rdMap;
-
- pMap->hLastResource = nil;
- pMap->lastResID = 0;
- pMap->lastResType = '????';
- pMap->lastResRef = 0;
- return noErr;
-
- }//RDInvalResCache
-